package com.zklh.leetcode.interviewTop150;

import java.util.HashMap;
import java.util.Map;

/**
 * 同构字符串
 * author: tongnan
 * date: 2024/8/5
 */
public class Solution205 {
    public boolean isIsomorphic(String s, String t) {
        Map<Character, Character> sCharToTChar = new HashMap<>();
        Map<Character, Character> tCharToSChar = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            if (sCharToTChar.containsKey(s.charAt(i)) && sCharToTChar.get(s.charAt(i)) != t.charAt(i) || tCharToSChar.containsKey(t.charAt(i)) && tCharToSChar.get(t.charAt(i)) != s.charAt(i)) {
                return false;
            } else {
                sCharToTChar.put(s.charAt(i), t.charAt(i));
                tCharToSChar.put(t.charAt(i), s.charAt(i));
            }
        }
        return true;
    }
}
